import { AddMobileContactData } from '@/utils/common-api.js'
export default {
  data() {
    return {
      list: {},
      id: '',
      tipShow: false,
    }
  },
  created() {
    this.GetBusOrderDetails()
  },
  onLoad(op) {
    console.log(op.id)
    this.id = op.id
  },
  filters: {
    formatStoreType(data) {
      let text = ''
      switch (Number(data)) {
        case 0:
          text = '支付宝'
          break
        case 1:
          text = '微信'
          break
        case 2:
          text = '余额'
          break
        default:
          text = ''
          break
      }
      return text
    },
  },
  methods: {
    timLogin() {
      // console.log('登录tim:', this.$store.state.news.userId)
      this.tim
        .login({
          userID: this.$store.state.news.userId,
          userSig: this.$store.state.news.userSig,
        })
        .then((res) => {
          //登录成功后 更新登录状态
          this.$store.commit('news/toggleIsLogin', true)
          //tim 返回的用户信息
          // uni.setStorageSync('userTIMInfo', JSON.stringify(res.data))
          // this.$store.commit('createConversationActive', item.Tid)
        })
        .catch((err) => {
          console.warn('login error:', err) // 登录失败的相关信息
        })
    },
    concat(dataObj) {
      /* if (this.$store.state.isSDKReady) {
			  this.getCont3(getList)
			} else {
			  timLogin(() => {
			    this.getCont3(getList)
			  })
			} */
      if (this.pageFrom === 'chat') {
        uni.navigateBack()
        return
      }
      AddMobileContactData(this.$store.state.userInfoDetail.store.storeId)
      // 传和我聊天人的信息
      this.$store.commit('news/createConversationActive', {
        user: dataObj.account_name, //店铺名称
        img: dataObj.headportrait, //店铺头像
        lastTime: '', //
        userId: dataObj.account_id, //店铺id
        conversationID: 'C2C' + dataObj.account_id,
      })
      this.$store.commit('news/setCardInfo', {
        imgSrc: dataObj.brand_img,
        name: dataObj.brand_name + ' ' + dataObj.configuration_name,
        price: dataObj.amount_payable,
        type: 'afterSales',
      })
      uni.navigateTo({
        url:
          '/pages_news/contactSeller/contactSeller?user=' +
          dataObj.account_name +
          '&pageId=' +
          dataObj.id +
          '&tab=0',
      })
    },
    phone(num) {
      uni.makePhoneCall({
        phoneNumber: num,
      })
    },
    // 点击温馨提示的我知道了按钮
    okey() {
      this.tipShow = false
      this.id = ''
      uni.navigateTo({
        url: '/pages_afterSales/createToStoreRecord/createToStoreRecord',
      })
    },
    returnTime(time) {
      if (time) {
        return time.split('T')[0] + ' ' + time.split('T')[1]
      }
    },
    async GetBusOrderDetails() {
      try {
        let data = {
          orderid: this.id,
        }
        const res = await this.$api.afterSales.GetBusOrderDetails(data)
        this.list = res.data
        console.log(res.data)
      } catch (e) {
        setTimeout(() => {
          uni.navigateBack({
            delta: 1,
          })
        }, 1000)
      }
    },
    // 复制
    copy() {
      uni.setClipboardData({
        data: this.list.order_no,
        success: (res) => {
          console.log(res)
          this.$u.toast('复制成功')
        },
        fail: (err) => {
          console.log(err)
          this.$u.toast('复制失败')
        },
      })
    },
    goPage() {
      this.$api.afterSales
        .getArrivalInfo({
          orderNo: this.id,
        })
        .then((res) => {
          console.log(res)
          if (res.data.userInfo) {
            this.$store.commit('afterSales/setUserInfo', res.data.userInfo)
          }
          this.$store.commit('afterSales/setServeAndQueue', {
            service: res.data.service,
            queue: res.data.queue,
          })
          if (res.data.carList.length) {
            this.$store.commit('afterSales/setArrivalCar', res.data.carList[0])
            this.$store.commit('afterSales/setCarList', res.data.carList)
          }
          if (res.data.userInfo && res.data.userInfo.orderCount > 0) {
            this.id = ''
            uni.navigateTo({
              url:
                '/pages_afterSales/createToStoreRecord/createToStoreRecord?isPackage=0',
            })
          } else {
            this.tipShow = true
          }
        })
    },
  },
}
